package com.yangjie.autotest.util;

import java.lang.reflect.Field;

public class ReflectionUtil {
	// public Object invodeMethod(Object obj, String methodName, Params params)
	// {
	// Class objClass = obj.getClass();
	// Method[] methods = objClass.getMethods();
	// for(int i = 0; i < methods.length; i++) {
	// Method method = methods[i];
	// if(method.getName().equals(methodName)) {
	// method.get
	// }
	// }
	// }

	public static Field getField(Class classVar, String fieldName) {
		Field[] fields = classVar.getDeclaredFields();
		for (Field field : fields) {
			String name = field.getName();
			if (name.equalsIgnoreCase(fieldName)) {
				return field;
			}
		}
		if (classVar.getName().equals("java.lang.Object")) {
			return null;
		} else {
			return getField(classVar.getSuperclass(), fieldName);
		}
	}

	public static Object getProperty(Object obj, String fieldName) throws Exception {
		Field field = getField(obj.getClass(), fieldName);
		if (field != null) {
			field.setAccessible(true);

			return field.get(obj);
		}

		return null;
	}
}
